package util;

import java.io.IOException;

import org.apache.commons.io.IOUtils;

public class ClassUtils {
    
    /**
     * @param clazz
     * @param name
     * @return
     * @author Mykhaylo Adamovych
     */
    public static String getResourceAsString(final Class<?> clazz, final String name) {
        try {
            return IOUtils.toString(clazz.getResourceAsStream(name));
        } catch (IOException e) {
            throw new RuntimeException("Can not read resource " + name);
        }
    }
    
    /**
     * @param clazz
     * @param name
     * @param charset
     * @return
     * @author Mykhaylo Adamovych
     */
    public static String getResourceAsString(final Class<?> clazz, final String name, final String charset) {
        try {
            return IOUtils.toString(clazz.getResourceAsStream(name), charset);
        } catch (IOException e) {
            throw new RuntimeException("Can not read resource " + name);
        }
    }
}
